import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import kotlinx.coroutines.launch

fun main() = application {
    Window(
        onCloseRequest = ::exitApplication,
        title = "Demo",

        //设置窗口大小，并居中
        state = WindowState(size = DpSize(1080.dp, 720.dp), position = WindowPosition(alignment = Alignment.Center)),
    ) {
        DemoScreen()
    }
}


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DemoScreen() {
    val snackbarState = remember { SnackbarHostState() }
    val scope = rememberCoroutineScope()

    Scaffold(
        snackbarHost = { SnackbarHost(snackbarState) },
        topBar = {
            TopAppBar(
                title = {
                    Text(
                        text = "创建传输任务",
                        fontSize = 18.sp
                    )
                }
            )
        }
    )
    { padding ->
        Column(modifier = Modifier.padding(padding)) {
            Button(onClick = {
                scope.launch {
                    snackbarState.showSnackbar(
                        message = "操作成功",
                        withDismissAction = true,
                        duration = SnackbarDuration.Short
                    )
                }
            }) {
                Text("显示 Snackbar")
            }
        }
    }

}
